package com.geostart.constructionland.system.controller;

import com.geostar.constructionland.common.entity.lockInfo.RedisInfoPage;
import com.geostar.constructionland.common.entity.lockInfo.RedisLockVo;
import com.geostar.constructionland.common.entity.response.ExtJsAjaxResponse;
import com.geostart.constructionland.system.mapper.JsydBpxxMapper;
import com.geostart.constructionland.system.service.RedisLockService;
import com.geostart.constructionland.system.util.RedisServiceUtil;
import com.geostart.constructionland.system.util.TimeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

import static java.util.stream.Collectors.toList;

/**
 * @author chengan
 * @description
 */
@Controller
@RequestMapping(path = "/redislock")
public class RedisLockController {

    @Autowired
    RedisServiceUtil redisService;

    @Autowired
    RedisLockService redisLockService;

    @Autowired
    JsydBpxxMapper jsydBpxxMapper;

    @Value("${spring.redis.key.prefix.token}")
    private String redisTokenPrefix;


    @GetMapping(path = "/profile")
    public String index() {
        return "profile/redisLock_profile";
    }



    @PostMapping("/getRedisInfo")
    @ResponseBody
    ExtJsAjaxResponse redisLockInfoPage(@NotBlank(message = "页码不能为空") @RequestParam(value = "page") int pageNo,
                                        @NotBlank(message = "每页数量不能为空") @RequestParam(value = "limit") int pageNum
            , @RequestParam(required = false) String query_ajid
            , @RequestParam(required = false) String query_xmmc) {
        return redisLockService.redisLockPage(pageNo,pageNum,query_ajid,query_xmmc);
    }


    @GetMapping("/delete")
    @ResponseBody
    ExtJsAjaxResponse deleteRedis(String ajid){
        boolean flag = redisService.delete(redisTokenPrefix + "_" + ajid);
        ExtJsAjaxResponse extJsAjaxResponse =null;
        if(flag){
            extJsAjaxResponse = ExtJsAjaxResponse.createBySuccess("删除成功！");
        }else{
            extJsAjaxResponse = ExtJsAjaxResponse.createByErrorMessage("删除失败！");
        }
        return extJsAjaxResponse;
    }


}
